<template>
  <div class="app-container"
       v-loading.fullscreen.lock="allLoading"
       element-loading-text="拼命处理中,请耐心等待"
       element-loading-spinner="el-icon-loading"
       element-loading-background="rgba(0, 0, 0, 0.8)"
  >
    <el-dialog :close-on-click-modal="changeBitFlagIsNone" :title="mainDialogInfo.title" :visible.sync="showDialog"
               width="700px" append-to-body @close="closeDialog">
      <el-form ref="form" :disabled="changeBitFlagIsNone" :model="form" :rules="rules" label-width="120px">

        <el-table v-loading="lookupTable.loading" :data="lookupTable.list" :show-header="false"  highlight-current-row @row-dblclick="handleSelect">
          <el-table-column label="" align="center" prop="vText" :show-overflow-tooltip="true" />
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="cancelMainDialog">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import { sksDialogFormMixin } from 'sks-plugin-el-erp/lib/dialog-form'
import { mergeFromObject } from 'sks-plugin-el-erp/lib/core'
import { newSksTable } from 'sks-plugin-el-erp/lib/sks-model-utils'
import {  lookupAIAgentUseChat,  updateAIAgent } from '@/api/ai'

//用于选择模型
export default {
  name: "ChatSelectAiAgentDialog",
  components: {
  },
  mixins: [
    sksDialogFormMixin,
  ],
  data() {
    return {
      defaultForm: {
        id: undefined,
        ai_model_id: undefined,
        name: undefined,
        description: undefined,
        emoji: undefined,
        tools: undefined,
        group: undefined,
        agent_ids: undefined,
        system_prompt: undefined,
        summarize_prompt: undefined,
        created_at: undefined,
        updated_at: undefined,
      },
      defaultFormNotNull: {
        virtualDocumentList: [],
      },

      rules: {
      },
      lookupTable: mergeFromObject(newSksTable(),{
        queryParams:{
          pageNum: 1,
          pageSize: 9999,
          ai_api_id: undefined,
        },
      })
    };
  },
  methods:{
    showToSelect({extra,dialogInfo,virtualChangeBitFlag=this.sksUtils.CHANGE_BIT_FLAG.none}){
      let data={}
      this.getMainList()
      this.show({
        extra: extra,
        form: this.sksUtils.mergeFromObject({},data,{
          virtualChangeBitFlag: virtualChangeBitFlag,
        }),
        dialogInfo: dialogInfo
      })

    },
    getMainList(){
      let queryParams = this.lookupTable.queryParams;
      this.sksUtils.resetSksTableBefore(this.lookupTable)
      lookupAIAgentUseChat(queryParams).then(res=>{
        for (let item of res.list){
          item.vText=item.v_ai_model_info
        }
        this.sksUtils.setSksTableDataByPage(this.lookupTable,res)
      })

    },
    handleSelect(row){
      let data = this.sksUtils.mergeFromObject({}, row);
      if (!this.sksUtils.isNullOrUndefined(this.mainDialogInfo.selectCallback)) {
        this.mainDialogInfo.selectCallback({selectRow: data, ref: this})
        //this.showDialog=false
        return
      }
      this.closeDialog()
    },
  }
}
</script>

<style scoped>
</style>
